package com.alks.function.service.impl.pcfactorywork;

import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.core.date.DateTime;
import com.alks.common.aop.AutoPageAop;
import com.alks.common.data.dto.SysUserTokenDTO;
import com.alks.common.data.thread.UserIdThread;
import com.alks.common.utils.DateUtils;
import com.alks.common.utils.UserInfoUtil;
import com.alks.common.utils.beanutils.ArrayUtils;
import com.alks.common.utils.beanutils.BeanUtil;
import com.alks.common.utils.excelUtils.ExcelPoiUtils;
import com.alks.common.utils.excelUtils.ExcelUtils;
import com.alks.entity.data.entity.PcOutListPrice;
import com.alks.entity.data.enums.chengkong.DefineEnum;
import com.alks.entity.data.page.PageRecord;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.dto.chengKong.cost.PcOutListPrice2Dto;
import com.alks.function.data.dto.chengKong.cost.SdStyleProcessNewDto;
import com.alks.function.data.dto.chengKong.produce.LotNoDetailDto;
import com.alks.function.data.dto.chengKong.produce.PcOutListDto;
import com.alks.function.data.dto.pcfactorywork.PcOutListPriceDetailDto;
import com.alks.function.data.dto.pcfactorywork.PcOutListPriceDto;
import com.alks.function.data.request.chengKong.LotNoRequest;
import com.alks.function.data.request.chengKong.cost.InsertManufacturerRequest;
import com.alks.function.data.request.chengKong.cost.PcOutListPriceUpdateRequest;
import com.alks.function.data.request.factorywork.PcOutListPriceDetailRequest;
import com.alks.function.data.request.factorywork.PcOutListPriceRequest;
import com.alks.function.mapper.SdStyleColorPhotoMapper;
import com.alks.function.mapper.chengKong.PcLotHeadMapper;
import com.alks.function.mapper.chengKong.PcOutListMapper;
import com.alks.function.mapper.pcfactorywork.PcOutListPriceMapper;
import com.alks.function.service.pcfactorywork.IPcOutListPriceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

import static com.alks.entity.data.enums.ResultCodeEnum.LOGIN_CONFIG_IS_NULL;

/**
 * <p>
 * 外发工艺单价 服务实现类
 * </p>
 *
 * @author ms
 * @since 2023-07-18
 */
@Service
@Slf4j
public class PcOutListPriceServiceImpl extends ServiceImpl<PcOutListPriceMapper, PcOutListPrice> implements IPcOutListPriceService {
    @Autowired
    PcOutListPriceMapper mapper;
    @Autowired
    SdStyleColorPhotoMapper photoMapper;

    @Resource
    private PcLotHeadMapper pcLotHeadMapper;

    @Resource
    private PcOutListMapper pcOutListMapper;

    /**
     * 分页-外发工艺指令
     *
     * @param request
     * @return
     */
    @Override
    public ResponseInfo<PageRecord> listPcOutPirce(PcOutListPriceRequest request) {
        SysUserTokenDTO sysUserTokenDTO = UserIdThread.get();
        /*分页初始化*/
        if (request.getPageNum() == null || request.getPageSize() == null) {
            request.setPageNum(1);
            request.setPageSize(10);
        }
        /*分页查询基础数据*/
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<PcOutListPriceDto> dto = mapper.listPcOutPrice(request, sysUserTokenDTO.getCompanyId());
        Page<PcOutListPriceDto> page = (Page<PcOutListPriceDto>) dto;
        /*返回结果封装*/
        PageRecord record = new PageRecord();
        record.setList(dto);
        record.setTotal(page.getTotal());
        return ResponseInfo.ok(record);
    }

    /**
     * 分页-外发工艺价格
     *
     * @param request
     * @return
     */
    @Override
    public ResponseInfo listPcOutPirceDetail(PcOutListPriceDetailRequest request) {
        if (request == null || BeanUtil.allIsEmpty(request)) {
            log.error("异常接口：listPcOutPirceDetail\n异常原因：传参异常【为空】");
            return ResponseInfo.error("传参异常", LOGIN_CONFIG_IS_NULL.getCode());
        }
        /*查询工艺价格*/
        List<PcOutListPrice> details = lambdaQuery()
                .eq(PcOutListPrice::getCompanyId, UserIdThread.get().getCompanyId())
                .eq(PcOutListPrice::getVendor, request.getVendor())
                .eq(PcOutListPrice::getLotNo, request.getLotNo())
                .eq(PcOutListPrice::getStyle, request.getStyle())
                .eq(PcOutListPrice::getColor, request.getColor())
                .list();
        /*算总价*/
        BigDecimal total = details.stream().map(PcOutListPrice::getPrice).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
        /*封装返回结果*/
        List<PcOutListPriceDetailDto> dtos = BeanUtil.copyList(details, PcOutListPriceDetailDto.class);
        Map<String, Object> map = new HashMap<>();
        map.put("total", total);
        map.put("price", dtos);
        return ResponseInfo.ok(map);
    }

    @Override
    public ResponseInfo listPcOutVendor(String vendor, String process) {
        /*查询厂商列表*/
        List<String> duty = lambdaQuery()
                .like(vendor != null && !vendor.isEmpty(), PcOutListPrice::getVendor, vendor)
                .groupBy(PcOutListPrice::getVendor)
                .list().stream().map(PcOutListPrice::getVendor).collect(Collectors.toList());
        /*查询工艺列表*/
        List<String> process1 = lambdaQuery()
                .eq(process != null && !process.isEmpty(), PcOutListPrice::getProcess, process)
                .groupBy(PcOutListPrice::getProcess)
                .list().stream().map(PcOutListPrice::getProcess).collect(Collectors.toList());
        Map<String, Object> map = new HashMap<>(2);
        map.put("duty", duty);
        map.put("process", process1);
        return ResponseInfo.ok(map);
    }

    @Override
    public ResponseInfo listOutDetailCheck(List<PcOutListPriceDetailRequest> request, Integer flag) {
        /*更新数据*/
        for (PcOutListPriceDetailRequest r : request) {
            /*判断数据健壮性*/
            List<PcOutListPrice> list = lambdaQuery().eq(PcOutListPrice::getLotNo, r.getLotNo())
                    .eq(PcOutListPrice::getStyle, r.getStyle())
                    .eq(PcOutListPrice::getColor, r.getColor())
                    .eq(PcOutListPrice::getVendor, r.getVendor()).list();
            if (ArrayUtils.isEmpyt(list)) {
                return ResponseInfo.error("指令：" + r.getLotNo() + "不存在");
            }
            List<PcOutListPrice> unCheckList = list.stream()
                    .filter(a ->a.getCfmFlag()==null|| a.getCfmFlag().isEmpty())
                    .collect(Collectors.toList());
            if (ArrayUtils.isNoEmpyt(unCheckList)) {
                return ResponseInfo.error("指令：" + r.getLotNo() + "未检核");
            }
            List<PcOutListPrice> cfmList;
            switch (flag) {
                case 0:
                    cfmList = list.stream()
                            .filter(a -> "Y".equals(a.getCheckFlag()))
                            .collect(Collectors.toList());
                    break;
                case 1:
                    cfmList = list.stream()
                            .filter(a -> a.getCheckFlag()==null||a.getCheckFlag().isEmpty())
                            .collect(Collectors.toList());
                    break;
                default:
                    log.warn("\n异常接口：listOutDetailCheck\n异常原因：传参[flag]不符合规范");
                    return ResponseInfo.error("传参异常");
            }
            if (ArrayUtils.isEmpyt(cfmList)) {
                String msg = flag == 1 ? "已审核" : "未审核";
                return ResponseInfo.error("指令"+r.getLotNo()+msg+",请勿重复操作");
            }
            lambdaUpdate().eq(PcOutListPrice::getCompanyId, UserIdThread.get().getCompanyId())
                    .eq(PcOutListPrice::getLotNo, r.getLotNo())
                    .eq(PcOutListPrice::getStyle, r.getStyle())
                    .eq(PcOutListPrice::getColor, r.getColor())
                    .eq(PcOutListPrice::getVendor, r.getVendor())
                    .eq(PcOutListPrice::getCfmFlag, "Y")
                    .eq(flag == 0, PcOutListPrice::getCheckFlag, "Y")
                    .isNull(flag == 1, PcOutListPrice::getCheckFlag)
                    .set(flag == 1, PcOutListPrice::getCheckDate, DateTime.now())
                    .set(flag == 1, PcOutListPrice::getCheckFlag, "Y")
                    .set(flag == 1, PcOutListPrice::getCheckUser, UserIdThread.get().getUserId())
                    .set(flag == 0, PcOutListPrice::getCheckDate, null)
                    .set(flag == 0, PcOutListPrice::getCheckFlag, null)
                    .set(flag == 0, PcOutListPrice::getCheckUser, null)
                    .update();
        }
        return ResponseInfo.ok();
    }

    /**
     * 外发工艺单价查询
     *
     * @param request
     * @return
     */
    @Override
    @AutoPageAop
    public ResponseInfo OutsourcingProcessInquiry(PcOutListPriceRequest request) {
        Map map = new HashMap();
        request.setCompanyId(UserIdThread.get().getCompanyId());
        List<PcOutListPrice2Dto> priceList = mapper.getPcOutListPriceList(request);
        BigDecimal count = mapper.getPcOutListPriceCountList(request);
        if (priceList.size() > 0) {
            for (PcOutListPrice2Dto t : priceList) {
                if (t.getCfmFlag() != null && t.getCfmFlag().equals("Y")) {
                    t.setCfmFlag("已检核");
                }
            }
        }
        PageInfo pageInfo = new PageInfo<>(priceList);
        map.put("priceList", priceList);
        map.put("total", pageInfo.getTotal());
        map.put("count", count);
        return ResponseInfo.ok(map);
    }

    /**
     * 取指令外发项目
     *
     * @param request
     * @return
     */
    @Override
    public ResponseInfo TakeInstructionsForOutsourcingProjects(LotNoRequest request) {
        if (ObjectUtils.isEmpty(request.getLotNo())) {
            return ResponseInfo.error("请输入指令!");
        }
        String companyId = UserIdThread.get().getCompanyId();
        LotNoDetailDto lotNoDetail = pcLotHeadMapper.getLotNoDetail(request.getLotNo(), companyId);
        if (ObjectUtils.isEmpty(lotNoDetail)) {
            return ResponseInfo.error("请输入正确指令!");
        }
        //查询外加工项目列表
        List<PcOutListDto> projectsList = pcOutListMapper.getOutsourcedProjectsList();
        if (!ObjectUtils.isEmpty(projectsList)) {
            PcOutListPriceRequest req = new PcOutListPriceRequest();
            req.setLotNo(request.getLotNo());
            req.setCompanyId(companyId);
            //筛选指令外发项目
            req.setFlag(3);
            List<PcOutListPrice2Dto> priceList = mapper.getPcOutListPriceList(req);
            if (ObjectUtils.isEmpty(priceList)) {
                List<PcOutListPrice> list = getPcOutListPrices(request.getLotNo(), lotNoDetail, projectsList);
                if (!ObjectUtils.isEmpty(list)) {
                    mapper.addPcOutListPrice(list);
                }
            } else {
                List<PcOutListPrice> list = new ArrayList<>();
                for (PcOutListDto project : projectsList) {
                    boolean found = false;
                    // 遍历priceList，查找是否存在相同序号的记录
                    for (PcOutListPrice2Dto price : priceList) {
                        String priceSeqPrefix;
                        if (project.getPartSeq() < 10) {
                            priceSeqPrefix = String.valueOf(price.getSeqNo()).substring(String.valueOf(price.getSeqNo()).length() - 1);
                        } else {
                            priceSeqPrefix = String.valueOf(price.getSeqNo()).substring(String.valueOf(price.getSeqNo()).length() - 2);
                        }
                        if (String.valueOf(project.getPartSeq()).equals(priceSeqPrefix)) {
                            found = true;
                            break;
                        }
                    }
                    // 如果不存在相同序号的记录，则新增到PcOutListPrice对象中
                    if (!found) {
                        PcOutListPrice pcOutListPrice = getPcOutListPrice(request.getLotNo(), lotNoDetail, project);
                        list.add(pcOutListPrice);
                    }
                }
                if (!ObjectUtils.isEmpty(list)) {
                    mapper.addPcOutListPrice(list);
                }
            }
        }
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 新增对象集合
     *
     * @param lotNo        指令
     * @param lotNoDetail  指令型体颜色资料
     * @param projectsList 外发项目
     * @return
     */
    private List<PcOutListPrice> getPcOutListPrices(String lotNo, LotNoDetailDto lotNoDetail, List<PcOutListDto> projectsList) {
        List<PcOutListPrice> list = projectsList.stream().map(t -> {
            return getPcOutListPrice(lotNo, lotNoDetail, t);
        }).collect(Collectors.toList());
        return list;
    }

    /**
     * 对单个新增对象进行处理
     *
     * @param lotNo       指令
     * @param lotNoDetail 指令型体颜色资料
     * @param t           单个外加工项目
     * @return
     */
    private PcOutListPrice getPcOutListPrice(String lotNo, LotNoDetailDto lotNoDetail, PcOutListDto t) {
        PcOutListPrice pcOutListPrice = getPcOutListPriceDetail(lotNo, lotNoDetail);
        if (t.getPartSeq() != null) {
            if (t.getPartSeq() < 10) {
                pcOutListPrice.setSeqNo(BigDecimal.valueOf(Long.parseLong("10" + t.getPartSeq())));
            } else {
                pcOutListPrice.setSeqNo(BigDecimal.valueOf(Long.parseLong("1" + t.getPartSeq())));
            }
        }
        pcOutListPrice.setPartName(t.getPartName());
        return pcOutListPrice;
    }

    /**
     * 取工艺外发项目
     *
     * @param request
     * @return
     */
    @Override
    public ResponseInfo TakeProcessOutsourcingProjects(LotNoRequest request) {
        if (ObjectUtils.isEmpty(request.getLotNo())) {
            return ResponseInfo.error("请输入指令!");
        }
        String companyId = UserIdThread.get().getCompanyId();
        LotNoDetailDto lotNoDetail = pcLotHeadMapper.getLotNoDetail(request.getLotNo(), companyId);
        if (ObjectUtils.isEmpty(lotNoDetail)) {
            return ResponseInfo.error("请输入正确指令!");
        }
        List<SdStyleProcessNewDto> newList = mapper.getSdStyleProcessNewList(lotNoDetail.getStyle(), lotNoDetail.getColor(), companyId);
        if (ObjectUtils.isEmpty(newList)) {
            return ResponseInfo.error("该指令没有设定外发工艺,请先处理!");
        }
        String flag = mapper.getSdStyleProcessHead(lotNoDetail.getStyle(), lotNoDetail.getColor(),companyId);
        if (!"Y".equals(flag)) {
            return ResponseInfo.error("该指令型体工艺未检核!");
        }
        PcOutListPriceRequest req = new PcOutListPriceRequest();
        req.setLotNo(request.getLotNo());
        req.setCompanyId(companyId);
        //筛选外发工艺资料
        req.setFlag(2);
        List<PcOutListPrice2Dto> priceList = mapper.getPcOutListPriceList(req);
        if (ObjectUtils.isEmpty(priceList)) {
            List<PcOutListPrice> list = filterAndSelectMinSeqNo(getPcOutListPriceToPartName(newList, request.getLotNo(), lotNoDetail));
            if (!ObjectUtils.isEmpty(list)) {
                mapper.addPcOutListPrice(list);
            }
        } else {
            List<PcOutListPrice> list = filterAndSelectMinSeqNo(getPcOutListPriceToPartName(newList, request.getLotNo(), lotNoDetail));
            List<PcOutListPrice> PcOutListPrices = new ArrayList<>();
            for (PcOutListPrice t : list) {
                boolean found = false;
                for (PcOutListPrice2Dto t2 : priceList) {
                    if (t.getPartName().equals(t2.getPartName())) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    PcOutListPrices.add(t);
                }
            }
            if (!ObjectUtils.isEmpty(PcOutListPrices)) {
                mapper.addPcOutListPrice(PcOutListPrices);
            }
        }
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 处理相同工序的外发工艺
     *
     * @param list
     * @return
     */
    public List<PcOutListPrice> filterAndSelectMinSeqNo(List<PcOutListPrice> list) {
        Map<String, PcOutListPrice> minSeqNoMap = new HashMap<>();
        // 遍历列表,只保留每个partName对应的seqNo最小的PcOutListPrice对象
        for (PcOutListPrice pcOutListPrice : list) {
            String partName = pcOutListPrice.getPartName();
            if (!minSeqNoMap.containsKey(partName) || pcOutListPrice.getSeqNo().compareTo(minSeqNoMap.get(partName).getSeqNo()) < 0) {
                minSeqNoMap.put(partName, pcOutListPrice);
            }
        }
        return new ArrayList<>(minSeqNoMap.values());
    }

    /**
     * 对外发工艺资料设置通用信息
     *
     * @return
     */
    public PcOutListPrice getPcOutListPriceDetail(String lotNo, LotNoDetailDto lotNoDetail) {
        PcOutListPrice list = new PcOutListPrice();
        UserInfoUtil.UserInfo userInfo = UserInfoUtil.getUserInfo();
        list.setCompanyId(userInfo.getCompanyId());
        list.setSysUser(userInfo.getUserName());
        list.setSysDate(LocalDateTime.now());
        list.setLotNo(lotNo);
        list.setColor(lotNoDetail.getColor());
        list.setStyle(lotNoDetail.getStyle());
        return list;
    }

    /**
     * 对外发工艺资料进行取值
     *
     * @param newList     外发工艺工序
     * @param lotNo       指令
     * @param lotNoDetail 指令型体颜色资料
     * @return
     */
    public List<PcOutListPrice> getPcOutListPriceToPartName(List<SdStyleProcessNewDto> newList, String lotNo, LotNoDetailDto lotNoDetail) {
        List<PcOutListPrice> priceList = new ArrayList<>();
        try {
            for (SdStyleProcessNewDto t : newList) {
                for (int i = 1; i <= 10; i++) {
                    String process = "getProcess" + i;
                    String processValue = (String) t.getClass().getMethod(process).invoke(t);
                    if (!ObjectUtils.isEmpty(processValue)) {
                        PcOutListPrice list = getPcOutListPriceDetail(lotNo, lotNoDetail);
                        list.setSeqNo(new BigDecimal(i));
                        list.setProcess(processValue);
                        list.setPartName(processValue + t.getPartName());
                        priceList.add(list);
                    }
                }
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return priceList;
    }

    /**
     * 插入厂商
     *
     * @param request
     * @return
     */
    @Override
    public ResponseInfo InsertManufacturer(List<InsertManufacturerRequest> request) {
        if (ObjectUtils.isEmpty(request)) {
            return ResponseInfo.error("请选择记录!");
        }
        int size = request.size();
        int count = 0;
        int idCount = 0;
        int vendorCount = 0;
        for (InsertManufacturerRequest t : request) {
            if (t.getFlag() == 0) {
                count++;
            }
            if (!ObjectUtils.isEmpty(t.getId())) {
                idCount++;
            }
            if (!ObjectUtils.isEmpty(t.getVendor())) {
                vendorCount++;
            }
        }
        if (vendorCount != size) {
            return ResponseInfo.error("请输入厂商!");
        }
        if (idCount != size) {
            return ResponseInfo.error("id不能为空!");
        }
        if (count > 0) {
            return ResponseInfo.error("有" + count + "条记录已经检核!");
        }
        mapper.updateByVendor(request, LocalDate.now());
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 工艺删除
     *
     * @param id
     * @return
     */
    @Override
    public ResponseInfo ProcessDeletion(Integer id) {
        if (ObjectUtils.isEmpty(id)) {
            return ResponseInfo.error("id不能为空");
        }
        String pcOutListPriceFlag = mapper.getPcOutListPriceFlag(id);
        if (!ObjectUtils.isEmpty(pcOutListPriceFlag) && pcOutListPriceFlag.equals(DefineEnum.CHECKOUT_FLAG.getValue())) {
            return ResponseInfo.error("该工艺已检核,不能删除!");
        }
        mapper.deleteById(id);
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 打勾记录检核 0检核/1取消检核
     *
     * @param request
     * @param choose
     * @return
     */
    @Override
    public ResponseInfo CheckTheBoxToCheckTheRecord(List<InsertManufacturerRequest> request, Integer choose) {
        if (ObjectUtils.isEmpty(request)) {
            return ResponseInfo.error("请选择记录!");
        }
        int checkCount = 0;
        int unCheckCount = 0;
        int priceCount = 0;
        for (InsertManufacturerRequest t : request) {
            if (!ObjectUtils.isEmpty(t.getFlag())) {
                if (t.getFlag() == 0) {
                    checkCount++;
                } else {
                    unCheckCount++;
                }
            }
            if (ObjectUtils.isEmpty(t.getPrice()) || ObjectUtils.isEmpty(t.getVendor())) {
                priceCount++;
            }
        }
        switch (choose) {
            case 0:
                if (checkCount > 0) {
                    return ResponseInfo.error("有" + checkCount + "条记录已经检核,不能再次检核!");
                }
                if (priceCount > 0) {
                    return ResponseInfo.error("有" + priceCount + "条记录未填写厂商或单价!");
                }
                mapper.updateByCheck(request, UserInfoUtil.getUserInfo().getUserName(), LocalDateTime.now(), DefineEnum.CHECKOUT_FLAG.getValue());
                break;
            case 1:
                if (unCheckCount > 0) {
                    return ResponseInfo.error("有" + unCheckCount + "条记录未检核,不能取消检核!");
                }
                mapper.updateByCheck(request, null, null, null);
                break;
            default:
                return ResponseInfo.error("参数错误!");
        }
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 外发工艺单价修改
     *
     * @param request
     * @return
     */
    @Override
    public ResponseInfo ModificationOfOutsourcingUnitPrice(PcOutListPriceUpdateRequest request) {
        if (ObjectUtils.isEmpty(request.getId())) {
            return ResponseInfo.error("id不能为空!");
        }
        String pcOutListPriceFlag = mapper.getPcOutListPriceFlag(request.getId());
        if (!ObjectUtils.isEmpty(pcOutListPriceFlag) && pcOutListPriceFlag.equals(DefineEnum.CHECKOUT_FLAG.getValue())) {
            return ResponseInfo.error("该工艺已检核，不能修改!");
        }
        mapper.PcOutListPrice(request);
        return ResponseInfo.ok("操作成功!");
    }

    /**
     * 导出明细
     *
     * @param request
     * @param response
     * @return
     */
    @Override
    public void PcOutListPriceExport(PcOutListPriceRequest request, HttpServletResponse response) {
        request.setCompanyId(UserInfoUtil.getUserInfo().getCompanyId());
        List<PcOutListPrice2Dto> priceList = mapper.getPcOutListPriceList(request);
        if (!ObjectUtils.isEmpty(priceList)) {
            HashMap<String, Object> map = new HashMap();
            String fileName = "外发单价明细表_" + DateUtils.dateTimeNow() + ".xlsx";
            BigDecimal count = mapper.getPcOutListPriceCountList(request);
            map.put("mapList", priceList);
            map.put("count", count);
            try {
                TemplateExportParams templateParams = new TemplateExportParams("templates/外发单价明细表模板.xls", true);
                ExcelUtils.setResponseZF(response, fileName);
                Workbook workbook = ExcelPoiUtils.createExcelWorkbook(templateParams, map);
                ExcelPoiUtils.writeExcelToResponse(workbook, response);
            } catch (Exception e) {
                log.error("外发单价表导出失败, 错误信息: {}", e.getMessage());
            }
        }
    }
}
